layui.use(['form', 'table','layer'], function () {
    let $ = layui.jquery,
        form = layui.form,
        table = layui.table,
        util = layui.util,
        layer = layui.layer;
    let radiocheck = '';
    let rowdata = '';
    table.render({
        elem: '#clearId',
        url: '/loading/clearLocationStorage',
        method: 'get',
        width: '95%',
        //toolbar: '#toolbarDemo',
        //toolbar: 'default',
        totalRow: true, //开启合计行
        height: 'full-200',
        cellMinWidth: 50,
        request: {
            pageName: 'page' //页码的参数名称，默认：page
            , limitName: 'limit' //每页数据量的参数名，默认：limit
        },
        response: {
            statusName: 'code' //数据状态的字段名称，默认：code
            , statusCode: 0 //成功的状态码，默认：0
            , countName: 'totals' //数据总数的字段名称，默认：count
            , dataName: 'list' //数据列表的字段名称，默认：data
        },
        /*parseData: function(res){ //将原始数据解析成 table 组件所规定的数据，res为从url中get到的数据
            console.log(res);
        },*/
        /*defaultToolbar: ['filter', 'exports', 'print'],*/
        cols: [
            [
                {
                field: 'name', title: '库位名称', width: 100, sort: true, align: 'center', templet: function (d) {
                    return '<div style = "text-align:left">' + d.name + '</div>'
                }
            }
                , {
                field: 'locationNumber', title: '库位编号', width: 100, align: 'center', templet: function (d) {
                    return '<div style = "text-align:left">' + d.locationNumber + '</div>'
                }
            }
                , {
                field: 'reservedFor', title: '现存委托单号', width: 180, sort: true, templet: function (d) {
                    return '<div style = "text-align:left">' + d.reservedFor + '</div>'
                }
            }
                , {
                field: 'hierarchy', title: '库位路径', width: 400, templet: function (d) {
                    return '<div style = "text-align:left">' + d.hierarchy + '</div>'
                }
            }
            ,{fixed: 'right', width: 100, align:'center', toolbar: '#clearToolBar'}

            ]
        ],
        limit: 10,
        limits: [10, 20, 30, 40, 50],
        page: true
        //skin: 'line',
        //size:'lg',
        //even: true
    });


    // 监听搜索操作
    form.on('submit(data-search-btn)', function (data) {
        var result = "{'name':'"+ $("#name").val() +"'}";
        //var result = JSON.stringify(resultvalue);
        console.log(result);
        //执行搜索重载
        table.reload('clearId', {
            page: {
                curr: 1
            }
            , where: {
                keyword: result
            }
        }, 'list');

        return false;
    });

    //行操作（清空库位）
    table.on('tool(clearFilter)', function(obj){
        let data = obj.data;
        if(obj.event === 'clear'){
            //layer.alert('编辑行：<br>'+ JSON.stringify(data));
            /**开始清空库位**/
            let loading = parent.layer.load(2);
            $.ajax({
                type:"post",
                url:"/limsaction/clearLocationStorage",
                data:JSON.stringify(data),
                contentType:"application/json;charset=utf-8",
                dataType:"json",
                success:function(res){
                    console.log(res);
                    parent.layer.close(loading);
                    parent.layer.msg(res.msg);
                    //parent.layer.closeAll();
                }
            });
        }
    });


});